﻿using UnityEngine;
using System.Collections;
using System.IO;
using System.Text;

public class CsvFileWriter : StreamWriter
{
    // Methods
    public CsvFileWriter(Stream StreamOut) : base(StreamOut)
    {
    }

    public CsvFileWriter(string FileName) : base(FileName)
    {
    }

    public void WriteRow(CsvRow Row)
    {
        StringBuilder builder = new StringBuilder();
        bool flag = true;
        foreach (string str in Row)
        {
            if (!flag)
            {
                builder.Append(',');
            }
            if (str.IndexOfAny(new char[] { '"', ',' }) != -1)
            {
                builder.AppendFormat("\"{0}\"", str.Replace("\"", "\"\""));
            }
            else
            {
                builder.Append(str);
            }
            flag = false;
        }
        Row.LineText = builder.ToString();
        this.WriteLine(Row.LineText);
    }
}


